import { post } from '@/request'
import { proxy } from 'valtio'

interface Columns {
    // 排名
    rank: number
    // 店铺
    shop: string
    // 产品名称
    name: string
    // 销量数量
    sales: number
    // 单价
    price: number
    // 销售金额
    amount: number
    // 销售占比
    ratio: number
    // 环比销量
    ratioSales: number
}

interface ProductResponse {
    top10: Columns[]
    data: Columns[]
    saleRatio: {
        value: number
        name: string
    }[]
}

export const product = proxy({
    // 产品销量占比图
    salesRatio: {
        tooltip: {
            trigger: 'item'
        },
        legend: {
            top: '5%',
            left: 'center'
        },
        series: [
            {
                name: '产品销量占比',
                type: 'pie',
                radius: ['40%', '70%'],
                avoidLabelOverlap: false,
                label: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    label: {
                        show: true,
                        fontSize: 40,
                        fontWeight: 'bold'
                    }
                },
                labelLine: {
                    show: false
                },
                data: [
                    { value: 65, name: '劲脆鸡腿堡' },
                    { value: 30, name: '老北京鸡肉卷' },
                    { value: 5, name: '饮料' },
                ]
            }
        ]
    },
    // 产品销量排行
    salesRank_columns: [
        { title: '排名', key: 'rank', dataIndex: 'rank' },
        { title: '店铺', key: 'shop', dataIndex: 'rank' },
        { title: '产品名称', key: 'name', dataIndex: 'rank' },
        { title: '销量数量', key: 'sales', dataIndex: 'rank' },
        { title: '单价', key: 'price,', dataIndex: 'price' },
        { title: '销售金额', key: 'amount', dataIndex: 'rank' },
        { title: '销售占比', key: 'ratio', dataIndex: 'ratio' },
        { title: '环比销量', key: 'ratioSales', dataIndex: 'ratioSales' }
    ],
    // 产品销量表数据
    salesRank_data: [
        {
            rank: 1,
            shop: '肯德基',
            name: '劲脆鸡腿堡',
            sales: 10000,
            price: 10000,
            amount: 10000,
            ratio: 10000,
            ratioSales: 10000
        },
        {
            rank: 2,
            shop: '麦当劳',
            name: '老北京鸡肉卷',
            sales: 10000,
            price: 10000,
            amount: 10000,
            ratio: 10000,
            ratioSales: 10000
        },
        {
            rank: 3,
            shop: '汉堡王',
            name: '饮料',
            sales: 10000,
            price: 10000,
            amount: 10000,
            ratio: 10000,
            ratioSales: 10000
        }
    ],
    // 产品销量top10列
    salesRank_top10_columns: [
        { title: '排名', key: 'rank', dataIndex: 'rank' },
        { title: '产品名称', key: 'name', dataIndex: 'name' },
        { title: '销售数量', key: 'sales', dataIndex: 'sales' }
    ],
    // 产品销量top10
    salesRank_top10_data: [
        {
            rank: 1,
            name: '劲脆鸡腿堡',
            sales: 10000
        },
        {
            rank: 2,
            name: '老北京鸡肉卷',
            sales: 10000
        },
        {
            rank: 3,
            name: '汉堡',
            sales: 10000
        },
        {
            rank: 4,
            name: '饮料',
            sales: 10000
        },
        {
            rank: 5,
            name: '薯条',
            sales: 10000
        },
        {
            rank: 6,
            name: '可乐',
            sales: 10000
        },
        {
            rank: 7,
            name: '薯条',
            sales: 10000
        },
        {
            rank: 8,
            name: '薯条',
            sales: 10000
        },
        {
            rank: 9,
            name: '薯条',
            sales: 10000
        },
        {
            rank: 10,
            name: '薯条',
            sales: 10000
        }
    ],
    update: async (
        brand = '',
        area = '',
        shop = '',
        soucer = '',
        dateStr = '7'
    ) => {
        const { top10, data, saleRatio }: ProductResponse = await post(
            '/analysis/product',
            { brand, area, shop, soucer, dateStr }
        )
        product.salesRank_top10_data = top10
        product.salesRank_data = data
        product.salesRatio.series[0].data = saleRatio
    }
})
